import { GaRegExp, ruleInject, ruleInjectable } from "../InjectionRule";
import { blankRemove } from "../methods/blank-remove";
import { MakeListRule } from "../methods/make-list";

// TODO need async await Promise
// TODO need lambda
@ruleInjectable()
export default class functionRule extends GaRegExp {

	@ruleInject() private variableNameRule!: GaRegExp;

	@ruleInject() private executeDataRule!: GaRegExp;

	@ruleInject() private calcRule!: GaRegExp;

	@ruleInject() private genericRule!: GaRegExp;

	@ruleInject() private typeCalcRule!: GaRegExp;

	public RuleInit() {
		this.ParseRule([
			"func", this.Supply("FUNCTION"),
			"(&", "\\s", blankRemove, this.variableNameRule, ")?", blankRemove,
			this.genericRule,
			"\\(", ...MakeListRule(["(", this.variableNameRule, ")", blankRemove, "(&", ":", blankRemove, this.typeCalcRule, ")?"]), "\\)", blankRemove,
			"\\{", blankRemove,
			"((-", "(-", "(", "return", this.Supply("FUNCTION_RETURN"), "\\s", blankRemove, "(", this.calcRule, ")", ";", ")", "|", this.executeDataRule, ")", blankRemove, ")*)",
			"\\}",
		]);
	}

}
